/*
 * MODULE NAME:    mgr_link.h
 * DESCRIPTION:    Host Link Manager
 * AUTHOR:         Martin Mellody
 * DATE:           23 May 2000
 *
 * SOURCE CONTROL: $Id: mgr_link.h,v 1.2 2009/08/25 06:04:50 jianguo Exp $
 *
 * LICENSE:
 *     This source code is copyright (c) 2000-2002 RDA Microelectronics.
 *     All rights reserved.
 *
 */

#ifndef __MGR_LINK_H
#define __MGR_LINK_H

#include "mgr_devdb.h"

/* NON-API START */
/* below this line will not open to customer */

/* remote device database */
#define ROLE_SLAVE	1
#define ROLE_MASTER 2


/* The first 4 values match those defined in HCI Spec. */
#define MGR_DEVACTIVE			0
#define MGR_DEVHOLD				1
#define MGR_DEVSNIFF			2
#define MGR_DEVPARK				3
#define MGR_DEVPENDINGACTIVE		13
#define MGR_DEVPENDINGHOLD		14
#define MGR_DEVPENDINGSNIFF		15
#define MGR_DEVPENDINGEXITSNIFF	16
#define MGR_DEVPENDINGPARK		17
#define MGR_DEVPENDINGEXITPARK	18


/* Used for Writing Automatic Flush Timeout */
#define FLUSH_TO_UNSET       0
#define FLUSH_TO_SET_PENDING 1
#define FLUSH_TO_SET         2
/* Used for Writing Link Supervision Timeout values */
#define LINK_TO_UNSET        0
#define LINK_TO_SET_PENDING  1
#define LINK_TO_SET          2


/* Remote Device PIN Code Types */
#define MGR_ALLZEROPIN	  0
#define MGR_PRESETPIN     1
#define MGR_USERREQPIN    2

#define MGR_HCI_CONNREJECT_REASON 0x0D /* Reason code used for automatic rejection - 0x0d=limited resources*/

#define NUM_BYTES_LMP_FEATURES 8

typedef struct st_t_l2_acl_link rdabt_t_l2_acl_link;

struct st_t_BT_DeviceInfo;
struct st_t_BT_ConnectionInfo {
    
	u_int8 role; /* 1 = master, 0 = slave */
	
	u_int8 aclState; /* CONN_OPEN | CONN_CLOSED | CONN_PENDING */
	u_int16 aclHandle;
        u_int8 features[NUM_BYTES_LMP_FEATURES];

       u_int8 scoState[MGR_MAXNUM_SCOHANDLES]; /* CONN_OPEN | CONN_CLOSED | CONN_PENDING */
	u_int16 scoHandle[MGR_MAXNUM_SCOHANDLES];	

        u_int8 sniffTimer;
        u_int16 min_interval;
        u_int16 max_interval;
        u_int16 adjust_interval;
	u_int8 deviceMode; /* DEV_SNIFF | DEV_HOLD | DEV_PARK | DEV_ACTIVE */
    u_int16 interval;
	u_int8 authMode; /* MGR_UNTRUSTED | MGR_TRUSTED */
	u_int8 encryptionMode; /* CRPYT_DISABLED | CRYPT_P2PONLY | CRYPT_ALL */

       tid_t access_Tid;
       u_int8 accessProto;  /* L2CAP_PROTOCOLID | RFCOMM_PROTOCOLID | SDP_PROTOCOLID | TCSBIN_PROTOCOLID */
       u_int8 accessDirect;
       u_int8 accessLevel; /* MGR_NOUSER_INTERACTION | MGR_NOMITM_MIN_USERIF | MGR_NOMITM_ENCRYPTION | MGR_MITM_ENCRYPTION */
       u_int8 accessReqState;   /* ACCESS_REQ_PENDING | ACCESS_REQ_ENCRYPT_PENDING */
	u_int8 bondingState;  /* BOND_INACTIVE | BOND_PENDING */
    u_int8 bond_role;

	/* For setting the Flush Timeout on an ACL */
	u_int8 aclFlushTimeoutFlag;
	u_int16 aclFlushTimeout;
	tid_t flushTOCallbackTid;
	
	/* For setting the Link Supervision Timeout on an ACL */
	u_int8 aclLinkSupTimeoutFlag;
	u_int16 aclLinkSupTimeout;
	u_int16 aclLinkSupTimeoutNew;
	tid_t aclLinkSupTOCallbackTid;

       tid_t l2_connect_Tid;

	/* For setting the QoS parameters for an ACL */
	t_L2_ChannelFlowSpec *qosParams;
	t_L2_ChannelFlowSpec *qosParamsNew;
	tid_t qosSetupCallbackTid;
	
        struct st_t_BT_DeviceInfo *pDeviceInfo;

};



void rdabt_mgr_initialise_linklist(void);
void rdabt_mgr_free_all_linklist(void);


/* ACL functions */
t_api rdabt_mgr_createACL(t_bdaddr bdaddr, rdabt_t_l2_acl_link *l2cap_link);
t_api rdabt_mgr_releaseACL(u_int16 handle, u_int8 reason);

t_api rdabt_mgr_releaseAllACL(u_int8 reason);

t_api rdabt_update_sniff_timer(u_int16 handle);

t_api rdabt_set_sniff_interval(u_int16 handle, u_int16 min, u_int16 max, u_int16 adjust_interval);

/* QoS functions */
t_api rdabt_mgr_updateFlushTimeout(u_int16 handle, u_int16* outFlushTimeout);
t_api rdabt_mgr_updateLinkSupervisionTimeout(u_int16 handle, u_int16* linkTimeout);
t_api rdabt_updateQoS(u_int16 handle,t_L2_ChannelFlowSpec *p_flowSpec);

t_api rdabt_mgr_handle_link_event(t_DataBuf *buff);

struct st_t_BT_ConnectionInfo *rdabt_mgr_get_deviceEntryByHandle(u_int16 handle, u_int8 *linkType);

t_api rdabt_mgr_get_addressByHandle(u_int16 handle, t_bdaddr *bdaddr) ;

int  MGR_GetACLState(t_bdaddr addr) ;

#endif // __MGR_LINK_H

